
package jpoco.android;

import java.util.*;

import jpoco.client.*;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

public class ContactListView extends ListView
{
	protected AbstractListAdapter adapter;
	
	public ContactListView(final Context context, List<Contact> contacts)
	{
		this(context);
		setContacts(contacts);
	}

	public ContactListView(Context context)
	{
		super(context);
		
		this.setOnItemClickListener(new AdapterView.OnItemClickListener()
		{

			public void onItemClick(AdapterView<?> parent, View view, int position, long id)
			{
				ContactView cview = (ContactView) view;
				cview.toggle();
			}
			
		});
	}

	public void setContacts(List<Contact> contacts)
	{
		adapter = new ContactListAdapter(contacts)
		{

			@Override
			public View getView(int position, View convertView, ViewGroup parent)
			{
				Contact c = this.getItem(position);
				
				return new ContactView( ContactListView.this.getContext(), c);
			}
			
		};
		
		this.setAdapter(adapter);
		
	}


}
